package com.gy.def.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Description 自动构建api的东西
 * @author cyy
 * @date 2018/11/19 16:36
 * @Param
 */
@Configuration
@EnableSwagger2
// 下面是配置生产环境不显示swagger2
//@Profile({"local", "dev", "test"})
public class Swagger2 {

    @Value("${swagger.show}")
    private boolean swaggerShow;//是否启用swagger

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .enable(swaggerShow)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.gy.def.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("BookSend APIs")
                .description("api接口文档")
                .version("1.0")
                .build();
    }

}
